package com.example.library

import androidx.fragment.app.FragmentActivity

object PermissionX {
    private const val TAG="InvisibleFragment"
    fun request(activity:FragmentActivity,vararg permissions:String,callback: PermissionCallback){
        val fragmentManager = activity.supportFragmentManager
        val existedFragment = fragmentManager.findFragmentByTag(TAG)
       val fragment= if(null!=existedFragment){
            existedFragment as InvisibleFragment
        }else{
            val invisibleFragment = InvisibleFragment()
           //commit()方法并不会立即执行添加操作，因而无法保证下一行代码执行时
           //InvisibleF ragment 已经被添加到Activity 中了
            fragmentManager.beginTransaction().add(invisibleFragment, TAG).commitNow()
            invisibleFragment
        }
        //*，这个符号并不是指针的意思，而是表示将一个
        //数组转换成可变长度参数传递过去
        fragment.requestNow(callback,*permissions)
    }
}